# -*- coding: utf-8 -*-

import math

N=int(raw_input())

#nums=map(int, raw_input().split(' ')) #最后一个测试用例是带有多余空格的
nums=map(int, raw_input().strip().split(' '))
nums.sort()
nums.reverse()

m,n=0,0

for i in range(int(math.sqrt(N)), 0, -1):
    if N%i == 0:
        n=i
        m=N/i
        break


M=[]
for i in range(m+2):
    M.append([0]*(n+2))


leftbound=0
rightbound=n+1
upbound=1
downbound=m+1

direction='ToRight'
i,j = 1,1


for e in nums:
    M[i][j]=e
    if direction == 'ToRight':
        if j+1 == rightbound:
            direction = 'ToDown'
            rightbound=j
            i+=1
        else:
            j+=1
    elif direction == 'ToDown':
        if i+1 == downbound:
            direction = 'ToLeft'
            downbound=i
            j-=1
        else:
            i+=1
    elif direction == 'ToLeft':
        if j-1 == leftbound:
            direction = 'ToUp'
            leftbound=j
            i-=1
        else:
            j-=1
    elif direction == 'ToUp':
        if i-1 == upbound:
            direction = 'ToRight'
            upbound=i
            j+=1
        else:
            i-=1


for i in range(1, len(M)-1):
    print ' '.join(map(str, M[i][1:-1]))

